package com.zj.inoutput.service;

import com.zj.inoutput.common.SpringContextUtil;
import com.zj.inoutput.model.request.user.UserParam;
import com.zj.inoutput.model.response.user.UserExportDTO;
import com.zj.inoutput.service.user.UserService;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @author DuanYu <a>Email:z-houjie@qq.com</a>
 * @date 2022-02-08 15:19
 */
@Getter
@RequiredArgsConstructor
public enum ExportTopic {

    /**
     * 用户列表页
     */
    USER_LIST(1, UserParam.class, UserExportDTO.class, "用户数据", "export_user_slicing", p -> SpringContextUtil.getBean(UserService.class).findExportData((UserParam) p));


    private final Integer value;

    /**
     * 查询参数类型
     */
    private final Class<?> param;

    /**
     * 导出类型
     */
    private final Class<?> target;

    /**
     * 文件名称
     */
    private final String fileName;

    /**
     * 分片表地址
     */
    private final String location;

    /**
     * 数据查询方法
     */
    private final Function<Object, List<?>> function;


    public static final Map<Integer, ExportTopic> INSTANCE;

    static {
        Map<Integer, ExportTopic> dict = new HashMap<>(ExportTopic.values().length);
        for (ExportTopic export : ExportTopic.values()) {
            dict.put(export.value, export);
        }
        INSTANCE = dict;
    }

}
